package com.wenson.behavior.mediator;

/**
 * @ClassName: People
 * @Author: luowangcheng
 * @Date: 2024/6/16 9:30
 * @Description:
 */
public class People {
    private String name;
    private People other;

    public String getName() {
        return name;
    }

    public People(String name) {
        this.name = name; //初始化必须起名
    }

    public void connect(People other) {
        this.other = other; //连接方法中注入对方对象
    }

    public void talk(String msg) {
        other.listen(msg);//我方讲话，对方聆听
    }

    public void listen(String msg) {
        //聆听来自对方的声音
        System.out.println(other.getName() + " 对" + this.name + " 说：" + msg);
    }
}
